<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "user_drug_warehouse".
 *
 * @property int $id
 * @property int $user_id 用户id
 * @property int $user_drug_id 药品id
 * @property int $user_supplier_id 用户供货单位id
 * @property int $num 数量
 * @property string $in_price 进价
 * @property string $out_price 处方价
 * @property string $vip_price 医改价
 * @property string $product_coding 产品批号
 * @property string $produce_time 生产日期
 * @property string $expired_time 有效期
 * @property int $status 状态
 *
 * @property User $user
 * @property UserDrug $userDrug
 * @property UserSupplier $userSupplier
 * @property UserDrugWarehouseRecord[] $userDrugWarehouseRecords
 */
class UserDrugWarehouse extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'user_drug_warehouse';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['user_id', 'user_drug_id', 'user_supplier_id'], 'required'],
            [['user_id', 'user_drug_id', 'user_supplier_id', 'num', 'status'], 'integer'],
            [['product_coding', 'produce_time', 'expired_time'], 'safe'],
            [['in_price', 'out_price', 'vip_price'], 'string', 'max' => 10],
            [['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['user_id' => 'id']],
            [['user_drug_id'], 'exist', 'skipOnError' => true, 'targetClass' => UserDrug::className(), 'targetAttribute' => ['user_drug_id' => 'id']],
            [['user_supplier_id'], 'exist', 'skipOnError' => true, 'targetClass' => UserSupplier::className(), 'targetAttribute' => ['user_supplier_id' => 'id']],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'user_id' => '用户',
            'user_drug_id' => '药品',
            'user_supplier_id' => '用户供货单位',
            'num' => '数量',
            'in_price' => '进价',
            'out_price' => '处方价',
            'vip_price' => '医改价',
            'product_coding' => '产品批号',
            'produce_time' => '生产日期',
            'expired_time' => '有效期',
            'status' => '状态',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getUser()
    {
        return $this->hasOne(User::className(), ['id' => 'user_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getUserDrug()
    {
        return $this->hasOne(UserDrug::className(), ['id' => 'user_drug_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getUserSupplier()
    {
        return $this->hasOne(UserSupplier::className(), ['id' => 'user_supplier_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getUserDrugWarehouseRecords()
    {
        return $this->hasMany(UserDrugWarehouseRecord::className(), ['user_drug_warehouse_id' => 'id']);
    }
}
